package demo1218.pm;

import java.util.Objects;

public class Employee implements Comparable<Employee>{
    private String name;
    private double salary;
    private int age;

    public Employee(String name, double salary, int age) {
        this.name = name;
        this.salary = salary;
        this.age = age;
    }

    public Employee() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Employee employee = (Employee) o;
        return Double.compare(employee.salary, salary) == 0 &&
                age == employee.age &&
                Objects.equals(name, employee.name);
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", salary=" + salary +
                ", age=" + age +
                '}';
    }

    /*
            (先比较薪资(从高到低)排序
            ,薪资相同比较年龄(从小到大))
             */
    @Override
    public int compareTo(Employee o) {
        if (this.salary>o.salary){
            return -1;  //返回-1，那么它就排前面
        }else if (this.salary<o.salary){
            return 1;
        }else {
            if (this.age>o.age){
                return 1;
            }else if (this.age<o.age){
                return -1;
            }else{
                return 0;
            }

        }

    }
}
